<template>
  <div>
      <!-- 通过gid查询商品信息 -->
      <span v-for="(item,i) in list" :key="i" @click="goInfo(item.gid)">{{item.name}}</span>
  </div>
</template>

<script>
    export default {
        data(){
            return {
                name: this.$route.params.name,
                list: [] //存放商品数据
            }
        },
        created(){
            this.getgoods()
        },
        computed: {
            
        },
        methods: {
            getgoods(){  //获取商品数据
                this.$store.state.goodslist.forEach(item=>{
                    if(item.fenlei == this.name){
                        this.list.push(item)
                    }
                    
                })
            },
            goInfo(gid){
                this.$router.push({name: "GoodsInfo",params: {gid}})
            }

        }
    }    

</script>

<style scoped>
    span {
        padding: 10px;
        display: inline-block;
        border: 1px solid purple;
        margin: 6px;
        
    }
    
   
</style>

